//
//  NSObject+propertyList.m
//  HZHome
//
//  Created by SunShine on 13-10-11.
//  Copyright (c) 2013年 xzysun. All rights reserved.
//

#import "NSObject+propertyList.h"
#import <objc/runtime.h>

@implementation NSObject (propertyList)

- (NSArray *)getPropertyList{
    if ([self class] == [NSObject class]) {
//        NSLog(@"递归到NSObject类了");
        return nil;
    }
    
    NSMutableArray *propertyList = [[NSMutableArray alloc] init];
    
    unsigned int outCount, i;
    
    objc_property_t *properties = class_copyPropertyList([self class], &outCount);
    
    for(i = 0; i < outCount; i++) {
        
        objc_property_t property = properties[i];
        
        NSString *eachPropertyName = [[NSString alloc] initWithUTF8String:property_getName(property)];
        if (![eachPropertyName isKindOfClass:[NSNull class]]) {
            [propertyList addObject:eachPropertyName];
        } else {
            NSLog(@"propproperties null ");
        }
        
    }
    
    free(properties);
    
    return [propertyList arrayByAddingObjectsFromArray:[[self superclass] getPropertyList]];
}

@end
